<?php 
/**
 * QFrameWork
 *
 * @author: quyang
 * @date: 2010-1-17
 * @version: 1.0
 */
/**
 * Loader Class
 *
 */
class Loader 
{
	
	static public function load_Lib($name, $custom_path = false){	
		$file = Loader::get_fullpath($name, LIB_PATH, $custom_path);
		return getInstance($file,$name);
	}

	static public function load_Model($name, $custom_path = false){
		$file = Loader::get_fullpath($name, MODEL_PATH, $custom_path);
		return getInstance($file,$name);		
	}
	
	static public function load_View($name, $page_data, $returnHTML = false, $custom_path = false){
		$file = Loader::get_fullpath($name, VIEW_PATH, $custom_path);
		extract($page_data);
		if($returnHTML){
			ob_start();
			require_once($file);			
			$html = ob_get_contents();
			@ob_end_clean();
			return $html;
		} else {
			require_once($file);
			exit;
		}
	}

	static public function load_Helper($name, $custom_path = false){	
		$file = Loader::get_fullpath($name, HELPER_PATH, $custom_path);
		require_once($file);
	}

	static public function load_Config($name, $custom_path = false){	
		$file = Loader::get_fullpath($name, CONFIG_PATH, $custom_path);
		require_once($file);
	}

	static public function get_fullpath($name, $ori_path, $custom_path){	
		if($custom_path){
			$file = $ori_path.$custom_path.DELIMITER.$name.EXT;
		} else {
			$file = $ori_path.$name.EXT;
		}
		if(!is_file($file))exit("File:[{$file}] not found.");
		return $file;
	}
}